<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        $orderId=$_REQUEST['orderId'];
        $status=$_REQUEST['status'];
		$sql="update ".$oto."_orders set orderStatus='{$status}' where userId='{$user_id}' and orderId='{$orderId}'";
		$result=$db->query($sql);
		if($status==4 || $status=='4')
		{
			$sql="SELECT * FROM ".$oto."_order_goods where orderId='{$orderId}'";
			$result2=$db->query($sql);
			while($row=$result2->fetch_assoc()){
				$order_info[]=$row;//将取得的所有数据赋值给person_info数组
			}
			if(isset($order_info))
			{
				for($i=0;$i<count($order_info);$i++)
				{
					$goods_id=$order_info[$i]['goodsId'];
					$goods_num=$order_info[$i]['goodsNums'];
					$sql="update ".$oto."_goods set saleCount=saleCount+'$goods_num' where goodsId='{$goods_id}'";
					$result2=$db->query($sql);
				}
			}
			$sql="SELECT * FROM ".$oto."_users where userId='{$user_id}'";
			$result2=$db->query($sql);
			while($row=$result2->fetch_assoc()){
				$users[]=$row;//将取得的所有数据赋值给person_info数组
			}
			$sql="SELECT * FROM ".$oto."_orders where orderId='{$orderId}'";
			$result2=$db->query($sql);
			while($row=$result2->fetch_assoc()){
				$orders[]=$row;//将取得的所有数据赋值给person_info数组
			}
			//增加商家余额
			$shopId=$orders[0]['shopId'];
			if(isset($orders))
			{
				$jia=$orders[0]['needPay'];
			}
			else
			{
				$jia=0;
			}
			$sql="update ".$oto."_shops set bizMoney=bizMoney+'$jia' where shopId='{$shopId}'";
			$result=$db->query($sql);
			
			$orderScore=$orders[0]['orderScore'];
			$order_no=$orders[0]['orderNo'];
			$z_user_score=$users[0]['userScore']+$orderScore;
			$time=time();

				$sql="update ".$oto."_users set userScore=userScore+'$orderScore' where userId='{$user_id}'";
				$result=$db->query($sql);
				$sql="INSERT INTO ".$oto."_score_record (`userid`,`orderNo`,`score`,`totalscore`,`time`,`IncDec`,`type`) VALUES ('$user_id','$order_no','$orderScore','$z_user_score','$time','1','1')";
	            $result=$db->query($sql);
			
		}
		$createTime=date('Y-m-d H:i:s');
		$content='';
		if($status==4 || $status=='4') $content='用户确认收货';
		$sql="INSERT INTO ".$oto."_log_orders (`orderId`,`logContent`,`logUserId`,`logType`,`logTime`) VALUES ('$orderId','$content','$user_id','0','$createTime')";
        $result2=$db->query($sql);
		echo json_encode($result);
?>